package com.sfdcj.se.meta.field;

import java.util.HashMap;

import com.sforce.soap._2006._04.metadata.CustomField;

/*
 <fields>
 <fullName>Field3__c</fullName>
 <label>�Q��</label>

 <referenceTo>Account</referenceTo>
 <relationshipLabel>Test</relationshipLabel>
 <relationshipName>Test</relationshipName>

 <type>Lookup</type>
 </fields>
 */

public class LookupType extends FieldType {

	static final String TYPE = "Lookup";

	public String referenceTo;

	public String relationshipLabel;

	public String relationshipName;

	public LookupType() {
		super();
	}

	public void appendXML() {
		buf.append("<referenceTo>" + referenceTo + "</referenceTo>");
		buf.append("<relationshipLabel>" + relationshipLabel
				+ "</relationshipLabel>");
		buf.append("<relationshipName>" + relationshipName
				+ "</relationshipName>");
		buf.append("<type>" + TYPE + "</type>");
	}

	@Override
	public String getTypeName() {
		return TYPE;
	}

	@Override
	public Object clone() {
		return new LookupType();
	}

	@Override
	public void setAttributes(HashMap<String, String> attributes) {
		referenceTo = attributes.get("referenceTo");
		relationshipLabel = attributes.get("relationshipLabel");
		relationshipName = attributes.get("relationshipName");
	}

	@Override
	public CustomField toCustomField() {
		CustomField field = new CustomField();
		field.setFullName(objectFullname + "." + fullname);
		field.setLabel(label);
		field.setReferenceTo(referenceTo);
		field.setRelationshipLabel(relationshipLabel);
		field.setRelationshipName(relationshipName);
		field.setType(com.sforce.soap._2006._04.metadata.FieldType.Lookup);
		return field;
	}	
}
